// Shared accross all firmwares
#define ASSERT_RESET

#if defined FIRMWARE_SBL
  #define MAKE_CRC_SHDW
#else 
  #define FAKE_CRC_SHDW
#endif

#define TC_LINKKEY_JOIN
#define SECURE 1
#define INCLUDE_REVISION_INFORMATION

// Save memory
#undef APS_MAX_GROUPS
#define APS_MAX_GROUPS 1
#undef NWK_MAX_BINDING_ENTRIES
#define NWK_MAX_BINDING_ENTRIES 1

/**
 * Disabling MULTICAST is required in order for proper group support.
 * If MULTICAST is not disabled, the group adress is not included in the APS header
 */
#define MULTICAST_ENABLED FALSE

/**
 * Reduce BCAST_DELIVERY_TIME and increase MAX_BCAST time.
 * BCAST_DELIVERY_TIME is the length of time a broadcast message is kept in the broadcast table
 * MAX_BCAST is the max number of messages that are in the broadcast table
 * If e.g. BCAST_DELIVERY_TIME = 1 second and MAX_BCAST = 10; 10 broadcast messages per second can be send.
 * 
 * Zigbee2mqtt has a fixed delay of 170ms between each command.
 * Therefore a BCAST_DELIVERY_TIME = 20 (= 2 seconds) and MAX_BCAST = 12 allows us to send
 * 2 / 12 = 1 group command per 166ms, which is just below the zigbee2mqtt delay.
 * Therefore the broadcast table will never get full.
 */
#define BCAST_DELIVERY_TIME 20
#undef MAX_BCAST // avoids incompatible redefinition of macro warning
#define MAX_BCAST 12

// See swra635.pdf
#define HAL_LCD FALSE
#define HAL_ADC FALSE

/** 
 * Enable MTO routing/source routing
 * Source routing could have issues: https://github.com/Koenkk/zigbee2mqtt/issues/1408
 */
#define CONCENTRATOR_ENABLE TRUE
#define CONCENTRATOR_DISCOVERY_TIME 60

#if defined SOURCE_ROUTING
  #define CONCENTRATOR_ROUTE_CACHE TRUE
  #define MAX_RTG_SRC_ENTRIES 40
  #undef MAX_RTG_ENTRIES
  #define MAX_RTG_ENTRIES 40
  #define MAX_NEIGHBOR_ENTRIES 16
  #define SRC_RTG_EXPIRY_TIME 0
#else
  #define CONCENTRATOR_ROUTE_CACHE FALSE
  #define MAX_RTG_SRC_ENTRIES 1 // Source table is not used, reduce to minimal size
  #undef MAX_RTG_ENTRIES
  #define MAX_RTG_ENTRIES 30
  #define MAX_NEIGHBOR_ENTRIES 12
#endif

// CC2531
#if defined FIRMWARE_CC2531
  #define CC2531ZNP
  #if defined SOURCE_ROUTING
    #define NWK_MAX_DEVICE_LIST 5
    #define MAXMEMHEAP 3309
  #else
    #define NWK_MAX_DEVICE_LIST 20
    #define MAXMEMHEAP 3285
  #endif
  
// CC2530
#elif defined FIRMWARE_CC2530
  #define HAL_UART_DMA_RX_MAX 128
  #define ENABLE_MT_SYS_RESET_SHUTDOWN
  #define ZTOOL_P1
  #define CC2530_MK

  #if defined SOURCE_ROUTING
    #define NWK_MAX_DEVICE_LIST 5
    #define MAXMEMHEAP 3189
  #else
    #define NWK_MAX_DEVICE_LIST 16
    #define MAXMEMHEAP 3277
  #endif

// CC2530 + CC2591
#elif defined FIRMWARE_CC2530_CC2591
  #define ENABLE_MT_SYS_RESET_SHUTDOWN
  #define ZTOOL_P1
  #define HAL_UART_DMA_RX_MAX 128
  #define HAL_PA_LNA

  #if defined SOURCE_ROUTING
    #define NWK_MAX_DEVICE_LIST 5
    #define MAXMEMHEAP 3187
  #else
    #define NWK_MAX_DEVICE_LIST 16
    #define MAXMEMHEAP 3275
  #endif

// CC2530 + CC2592
#elif defined FIRMWARE_CC2530_CC2592
  #define ENABLE_MT_SYS_RESET_SHUTDOWN
  #define ZTOOL_P1
  #define HAL_UART_DMA_RX_MAX 128
  #define HAL_PA_LNA_CC2592

  #if defined SOURCE_ROUTING
    #define NWK_MAX_DEVICE_LIST 5
    #define MAXMEMHEAP 3187
  #else
    #define NWK_MAX_DEVICE_LIST 16
    #define MAXMEMHEAP 3275
  #endif

#endif
